package com.enterprise.controller.api.cust;

import com.alibaba.fastjson.JSON;
import com.enterprise.controller.api.common.BaseResponse;
import com.enterprise.controller.api.cust.vo.CustserviceResp;
import com.enterprise.entity.Custservice;
import com.enterprise.service.CustserviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.List;


@Slf4j
@RequestMapping("/api/custservice")
@Controller("apiCustserviceController")
public class CustController {

    @Autowired
    private CustserviceService custserviceService;

    @ResponseBody
    @RequestMapping("/queryCustserviceList")
    public BaseResponse<List<CustserviceResp>> queryCarList(){
        BaseResponse response = new BaseResponse();
        List<Custservice> custserviceList = custserviceService.selectList(new Custservice());
        List<CustserviceResp> custserviceResps = new ArrayList<>();
        for (Custservice custservice:custserviceList) {
            CustserviceResp custserviceResp = new CustserviceResp();
            BeanUtils.copyProperties(custservice,custserviceResp);
            custserviceResp.setLogourl(BaseResponse.httpstr(custserviceResp.getLogourl()));
            custserviceResps.add(custserviceResp);
        }
        log.info("queryCustserviceList custserviceResps: {}" , JSON.toJSONString(custserviceResps));
        response.setData(custserviceResps);
        return response;
    }


    @ResponseBody
    @RequestMapping("/queryCustserviceView/{id}")
    public BaseResponse<CustserviceResp> queryCustserviceView(@PathVariable("id") String id){
        BaseResponse response = new BaseResponse();
        Custservice custservice = custserviceService.selectById(Integer.valueOf(id));
        CustserviceResp custserviceResp = new CustserviceResp();
        BeanUtils.copyProperties(custservice,custserviceResp);
        custserviceResp.setLogourl(BaseResponse.httpstr(custserviceResp.getLogourl()));
        log.info("queryCustserviceView custserviceResp: {}" , JSON.toJSONString(custserviceResp));
        response.setData(custserviceResp);
        return response;
    }


}
